package com.ma.test

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity


const val FIRST_MSG = "FIRST_MSG"
const val SECOND_MSG = "SECOND_MSG"
private const val REQUEST_CODE_THIRD = 100

@Suppress("DEPRECATION")

class MainActivity : AppCompatActivity() {

    private lateinit var textView: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)

        val first = findViewById<Button>(R.id.first)
        val editText = findViewById<EditText>(R.id.editText)


        textView = findViewById(R.id.textView)

        first.setOnClickListener {
            val intent = Intent(this, SecondActivity::class.java)
            intent.putExtra(FIRST_MSG, editText.text.toString())
            startActivity(intent)
        }
        val second = findViewById<Button>(R.id.second)
        second.setOnClickListener {
            val intent = Intent(this, ThirdActivity::class.java)
            startActivityForResult(intent, REQUEST_CODE_THIRD)
        }
        val third = findViewById<Button>(R.id.third)
        third.setOnClickListener {
            val intent = Intent(this, FourthActivity::class.java)
            startActivity(intent)
        }

        val fourth = findViewById<Button>(R.id.fourth)
        fourth.setOnClickListener {
            val intent = Intent(this, FifthActivity::class.java)
            startActivity(intent)
        }

    }

        //输入result自动回调
        @Deprecated("Deprecated in java")
        override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
            super.onActivityResult(requestCode, resultCode, data)
            if (requestCode == REQUEST_CODE_THIRD && resultCode == RESULT_OK) {
                textView.text = data?.getStringExtra(SECOND_MSG)
            }
        }

}
